package com.kalix.jyksh.record.biz;

import com.kalix.framework.core.impl.biz.GenericBizServiceImpl;
import com.kalix.framework.core.util.ConfigUtil;
import com.kalixjyksh.record.api.biz.IEquipmentRecordBeanService;
import com.kalix.ksh.record.api.dao.IEquipmentRecordBeanDao;
import com.kalix.ksh.record.api.model.ToInterface;
import com.kalix.jyksh.record.entities.EquipmentRecordBean;
import org.json.JSONArray;
import org.json.JSONObject;

/**
 *
 * 功能描述: 根据智能统计图数据需要格式，返回数据
 *
 * @auther: Whw
 * @date: 2019/1/14 0014 17:12
 * @param:
 * @return:
 */

public class EquipmentRecordServiceImpl extends GenericBizServiceImpl<IEquipmentRecordBeanDao, EquipmentRecordBean> implements IEquipmentRecordBeanService {
    public EquipmentRecordServiceImpl(){
        super.init(EquipmentRecordBean.class.getName());
    }

    public static String wsIp = (String) ConfigUtil.getConfigProp("FREEBOARD_IP","config.ksh.portconf");
    public static String wsPort =(String)ConfigUtil.getConfigProp("FREEBOARD_PORT","config.ksh.portconf");

// 智能统计图数据
    public String getEquipment() {

        String data=ToInterface.interfaceUtil("http://"+wsIp+":"+wsPort+"/om/statistics/overstep/summary","");
        JSONObject jsonObject = new JSONObject(data);
        Object patrolcount =  jsonObject.get("patrolcount");// 自动巡查
        Object oversteprate =  jsonObject.get("oversteprate");// 智维越界比例
        Object diagnosiscount =  jsonObject.get("diagnosiscount");// 执行智能诊断
        Object totalmo =  jsonObject.get("totalmo");//  总对象数
        Object overstepcount =  jsonObject.get("overstepcount");// 智维越界

        Double oversteprates = Double.parseDouble(oversteprate.toString());
        double over= oversteprates * 10 ;
        String overs = over + "%";

        JSONObject json = new JSONObject(getAllCycle());
        Object day =  json.get("1");// 新增日报表数
        Object week =  json.get("2");// 新增周报表数
        Object month =  json.get("3");// 新增月报表数
        Object objs =  json.get("6");// 新增其他报表数
        Object other =  json.get("4");//该属性无需关注
        Object object =  json.get("5"); //该属性无需关注


        JSONObject  l= new JSONObject();
        l.put("0","其他新增报表");
        l.put("1","新增月报表");
        l.put("2","新增周报表");
        l.put("3","新增日报表");
        l.put("4","执行智能诊断");
        l.put("5","自动巡查");
        l.put("6","智能越界");
        l.put("7","智能越界比例");



        JSONObject  list= new JSONObject();
        list.put("0",objs);
        list.put("1",month);
        list.put("2",week);
        list.put("3",day);
        list.put("4",diagnosiscount);
        list.put("5",patrolcount);
        list.put("6",overstepcount);
        list.put("7",overs);




        JSONArray jsonArray = new JSONArray();

        for(int i = 0; i < 8 ; i++ ) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("data",l.get(""+i));
            jsonObject1.put("title",list.get(""+i));
            jsonArray.put(jsonObject1);


        }
        return jsonArray.toString();
    }

    public String getAllCycle(){
        String string=ToInterface.interfaceUtil("http://"+wsIp+"/reportengine/rest/reports/count/allCycle","");

        return string;
    }

}
